<?php
if(!defined('ADMINPX') || !defined('ADMIN')) {
	exit('Access Denied');
}
$act=$_GET['act'];
$id=$_GET['id'];
$fid=$_GET[fid];
$aa=$_GET[aa];

if($act=='zjylok'){
	 if(empty($_POST['namem'])){
	    echo"内容不能为空<br/>";
	 }else if(!is_url($_POST['link'])){
		  echo"网址输入错误<br/>";
	 }else if($db->insert('link',array('id' => 'NULL' ,'fid' => $_POST[fid],'uip' => '0.0.0.0','name' => $_POST[name],'namem' => $_POST[namem],'url' => $_POST['link'],'click' => '0','jlick' => '0','logo' => $_POST[logo],'type' => $_POST[type],'check' => '0','time_a' => $time,'time_b' => $time ))){
	    echo"增加成功<br/>";
	 }else{
		  echo"增加失败<br/>";
	 }
   echo "正在自动返回.......<br/><a href=\"admin.php?action=link\">请手动返回</a><br/><meta http-equiv=refresh content='3;url=admin.php?action=link'>";
}else if($act=='zjyl'){
echo <<<end
<form method="POST" action="admin.php?action=link&act=zjylok&fid=$fid&$see">
网站名称:<input class="text" type="text" name="name" value="$row[title]"/><br/>
网站简称:<input class="text" type="text" name="namem" value="$row[name]"/>（两个中文字符）<br/>
网站地址:<input class="text" type="text" name="link" value="http://"/><br/>
网站图片:<input class="text" type="text" name="logo" value=""/><br/>
网站分类:   <select name='fid'>
end;

   $sql_lk=$db->query('link_class',"ORDER BY `px`  ",'');
   while($row=mysql_fetch_array($sql_lk)){
	    echo"<option value=".$row['id'].">".$row['name']."</option>";
   }

echo <<<end
</select><br/>
首页推荐:
<input type="radio" CHECKED name="type" value="0" />普通
<input type="radio" name="type" value="1" />固链
<input type="radio" name="type" value="2" />热门
<input type="radio" name="type" value="3" />推荐
<input type="radio" name="type" value="4" />兄弟
<br/>
<input class="submit" type="submit" value="增加友链" name="b1" />
</form>
end;
}else if($act=='zjflok'){
	 if(empty($_POST[name])){
	    echo"内容不能为空<br/>";
	 }else if($db->insert('website_statistics',array('id' => 'NULL' ,'px' => $_POST[px],'name' => $_POST[name]))){
	    echo"增加分类成功<br/>";
	 }else{
		  echo"增加分类失败<br/>";
	 }
   echo "正在自动返回.......<br/><a href=\"admin.php?action=link&\">请手动返回</a><br/><meta http-equiv=refresh content='3;url=admin.php?action=link&'>";
}else if($act=='zjfl'){
echo <<<end
<div class="admin">增加友链分类<br/></div>
<form method="POST" action="admin.php?action=link&act=zjflok" >
排序<input class="text" type="text" name="px" value="1" size=25/><br/>
名称<input class="text" type="text" name="name" value="" size=25/><br/>
<input class="submit" type="submit" value="确定增加分类" name="b1" />
</form>
end;
}else if($act=='xgflok'){
    	    if($db->update('link_class'," `name` = '$_POST[name]',`px` = '$_POST[px]' "," `id`= '$id'")){
	           echo"修改成功<br/>";
          }else{
		         echo"修改失败<br/>";
          }
    echo "正在自动返回.......<br/><a href=\"admin.php?action=link&\">请手动返回</a><br/><meta http-equiv=refresh content='3;url=admin.php?action=link&'>";
}else if($act=='scflts'){
	  echo "注意：删除友链分类直接删除分类下属友链！<br/>";
    echo "<a href=\"admin.php?action=link&act=scfl&id=$id\">确定删除</a><br/>";
    echo "<a href=\"admin.php?action=link&\">返回友链</a><br/>";
}else if($act=='scfl'){
    $db->delete('link_class'," `id` = '$id'");
    $db->delete('link'," `fid` = '$id'");
	  echo"删除成功<br/>";
    echo "正在自动返回.......<br/><a href=\"admin.php?action=link&\">请手动返回</a><br/><meta http-equiv=refresh content='3;url=admin.php?action=link&'>";
}else if($act=='scyl'){
    $db->delete('link'," `id` = '$id'");
	  echo"删除成功<br/>";
    echo "正在自动返回.......<br/><a href=\"admin.php?action=link\">请手动返回</a><br/><meta http-equiv=refresh content='3;url=admin.php?action=link'>";
}else if($act=='gd'){
     $row1=$db->get_one('link_class'," `id` ='$fid'",'');
echo <<<end
<div class="admin_a">
<form method="POST" action="admin.php?action=link&act=xgflok&id=$row1[id]" >
<input type="text" name="px" value="$row1[px]" size=1/>
<input type="text" name="name" value="$row1[name]" size=5/>
<input type="submit" value="修改" name="b1" />
</form>
<a href="admin.php?action=link&act=zjyl&fid=$row1[id]">增加友链</a> - 
<a href="admin.php?action=link&act=scflts&id=$row1[id]">删除</a><br/></div>
end;
   echo"<div class=\"admin\">分类友链内容<br/></div>";
   $num_count=$db->num_rows('link'," `fid` ='$fid' and `check` = '0'",'id');
   $list_num ="10";
   $num_start=page_num($list_num,$num_count);
   $sql_bbs  =$db->query('link'," `fid` ='$fid' and `check` = '0' ORDER BY `id` DESC LIMIT ".$num_start." , ".$list_num." ",'');
   $a        =$num_start+'1';
   while($row_c=mysql_fetch_array($sql_bbs)){
echo <<<end
<div class="admin_a">$row_c[name]
[<a href="admin.php?action=link&act=xgyl&id=$row_c[id]&fid=$fid">修改</a>
/ <a href="admin.php?action=link&act=scyl&id=$row_c[id]&fid=$fid">删除</a>]<br/></div>
end;
      $a++;
   }
   echo $page=page_link($list_num,$num_count);
}else if($act=='sh'){
	if($aa=='qb'){
		  $db->update('link'," `check` = '0' "," 1 ");
			echo "审核成功<br/>";
	}else if($aa=='id'){
		  $db->update('link'," `check` = '0' "," `id` ='$id' ");
			echo "审核成功<br/>";
	}
   echo"<div class=\"admin\">未审核站点</div>  (<a href=\"admin.php?action=link&act=sh&aa=qb&\">审核全部通过</a>)</br>";
   $num_count=$db->num_rows('link'," `check` = '1'",'id');
   $list_num ="10";
   $num_start=page_num($list_num,$num_count);
   $sql_bbs  =$db->query('link'," `check` = '1' ORDER BY `id` DESC LIMIT ".$num_start." , ".$list_num." ",'');
   $a        =$num_start+'1';
   while($row_c=mysql_fetch_array($sql_bbs)){
echo <<<end
$a .<a href="admin.php?action=link&act=xgyl&id=$row_c[id]&fid=$row_c[fid]">$row_c[namem]</a>[<a href="admin.php?action=link&act=sh&aa=id&id=$row_c[id]">审核通过</a> /
<a href="admin.php?action=link&act=scyl&id=$row_c[id]&fid=$fid">删除</a>]<br/>
end;
      $a++;
   }
   echo $page=page_link($list_num,$num_count);
}else if($act=='xgyl'){
	if($aa=='ok'){
		  $db->update('link',"`name` = '$_POST[name]',`namem` = '$_POST[namem]',`url` = '$_POST[links]',`type` = '$_POST[type]',`logo` = '$_POST[logo]',`fid` = '$_POST[fid]'"," `id` ='$id' ");
	  	echo "<font color=ff0000>修改成功</font><br/>";
	}
	$row=$db->get_one('link'," `id` ='$id'",'');
if($row[type] == '0'){ $a="CHECKED "; }else if($row[type] == '1'){ $b="CHECKED "; }else if($row[type] == '2'){ $c="CHECKED "; }elseif($row[type] == '3'){ $d="CHECKED "; }elseif($row[type] == '4'){ $f="CHECKED "; }

echo <<<haida
(<a href="$row[url]">前往该网站</a>)<br/>
<form method="POST" action="admin.php?action=link&act=xgyl&id=$id&aa=ok&fid=$fid">
站点名称:<input  class="text" type="text" name="name" value="$row[name]"/><br/>
网站简称:<input  class="text" type="text" name="namem" value="$row[namem]"/>（两个中文字符）<br/>
网站地址:<input  class="text" type="text" name="links" value="$row[url]"/><br/>
网站图片:<input  class="text" type="text" name="logo" value="$row[logo]"/><br/>
首页推荐:  
<input type="radio" $a name="type" value="0" />普通
<input type="radio" $b name="type" value="1" />固链
<input type="radio" $c name="type" value="2" />热门
<input type="radio" $d name="type" value="3" />推荐
<input type="radio" $f name="type" value="4" />兄弟
<br/>
网站分类:  
haida;
   $sql_lk=$db->query('link_class',"ORDER BY `px`  ",'');
   while($rowo=mysql_fetch_array($sql_lk)){
   	  $a='';
   	  if($rowo[id] == $row[fid]){ $a="CHECKED "; }
	    echo"<input type='radio' ".$a." name='fid' value=".$rowo['id']." />".$rowo['name']."";
   }

echo <<<haida
<br/>
<input  class="submit" type="submit" value="修改" name="b1" />
</form>
<a href="admin.php?action=link&act=scyl&id=$row[id]&fid=$fid">删除友链</a><br/>
haida;
if(!$fid){$fid=$row[fid];}
echo"<a href=\"admin.php?action=link&act=gd&fid=$fid\">友链分类</a><br/>";	
}else if($act=='sua'){
   $sqla  =$db->query('link',"1 ORDER BY RAND() LIMIT 0 ,10",'');
   $a='0';
   while($rowa=mysql_fetch_array($sqla)){
   	  if(Bingz_collection($rowa[url])){
      $db->update('link',"`click` = `click`+1 ,`time_a` ='$time' ","`id` ='$rowa[id]'");
      echo " $rowa[url] - <font color=ff0000>成功</font> - $rowa[click]+1</br>";
      }else{
      echo " $rowa[url] - <font color=ff0000>失败</font> - $rowa[click]+0</br>";
      }      
      
 	    $a++;
 	 }
   echo'<div class="admin_a">共刷量'.$a.'网站</div>';
}else if($act=='kqsh'){
   if(!$_POST[adminpost]){
	   echo"提交出错<br/>";
	 }else{
	   Bingz_config('link_config_post',$_POST['link_config_post'],'post');
	   Bingz_config('link_config_scsz',$_POST['link_config_scsz'],'post');
	   Bingz_config('link_config_ts',$_POST['link_config_ts'],'post');
	   echo"提交成功<br/>";
	 }
     echo "正在自动返回.......<br/><a href=\"admin.php?action=link\">请手动返回</a><br/><meta http-equiv=refresh content='3;url=admin.php?action=link&'>";
}else{
     $check=$db->num_rows('link'," `check` ='1' ",'id');
     echo'<div class="admin_a"><a href="admin.php?action=link&act=sua">一键刷量</a></div>';
     echo'<div class="admin">网站友链管理</div>
     <a href="admin.php?action=link&act=zjfl">增加分类</a>—
     <a href="admin.php?action=link&act=zjyl&fid=$row[id]">增加友链</a>—
     <a href="admin.php?action=link&act=sh">未审核</a>(<font color="ff0000">'.$check.'</font>)<br/>';
if(Bingz_config('link_config_post') == '1'){$aa='CHECKED';}else{$bb='CHECKED';}
if(Bingz_config('link_config_scsz') == '1'){$cc='CHECKED';}else{$dd='CHECKED';}
$link_config_ts=Bingz_config('link_config_ts');
if(!$link_config_ts){
	$link_config_ts='5';
}
echo <<<end
<form method="POST" action="admin.php?action=link&act=kqsh" >
提交审核:
     <input type="radio" $aa name="link_config_post" value="1" />开启
     <input type="radio" $bb name="link_config_post" value="0" />关闭<br/>
7天无数据删除:
     <input type="radio" $cc name="link_config_scsz" value="1" />开启
     <input type="radio" $dd name="link_config_scsz" value="0" />关闭<br/>
首页行显示条数<input type="text" name="link_config_ts" value="$link_config_ts" size=5/><br/>
<input  class="submit" type="submit" value="提交设置" name="adminpost" />
</form>
end;


echo <<<end
<div class="admin_b"><b>固链合作</b> </div>
end;
   echo '<div class="admin_a">&nbsp;&nbsp;&nbsp;&nbsp;';
   $sqla  =$db->query('link'," `type` = '1' and `check` = '0' ORDER BY `id` ",'');
   while($rowa=mysql_fetch_array($sqla)){
    echo "<a href=\"admin.php?action=link&act=xgyl&id=$rowa[id]&fid=$row[id]\">$rowa[namem]</a>-";
 	 }
   echo "</div>";
echo <<<end
<div class="admin_b"><b>热门聚焦</b> </div>
end;
   echo '<div class="admin_a">&nbsp;&nbsp;&nbsp;&nbsp;';
   $sqla  =$db->query('link'," `type` = '2' and `check` = '0' ORDER BY `id` ",'');
   while($rowa=mysql_fetch_array($sqla)){
    echo "<a href=\"admin.php?action=link&act=xgyl&id=$rowa[id]&fid=$row[id]\">$rowa[namem]</a>-";
 	 }
   echo "</div>";
echo <<<end
<div class="admin_b"><b>推荐网站</b> </div>
end;
   echo '<div class="admin_a">&nbsp;&nbsp;&nbsp;&nbsp;';
   $sqla  =$db->query('link'," `type` = '3' and `check` = '0' ORDER BY `id` ",'');
   while($rowa=mysql_fetch_array($sqla)){
    echo "<a href=\"admin.php?action=link&act=xgyl&id=$rowa[id]&fid=$row[id]\">$rowa[namem]</a>-";
 	 }
   echo "</div>";
echo <<<end
<div class="admin_b"><b>兄弟联盟</b> </div>
end;
   echo '<div class="admin_a">&nbsp;&nbsp;&nbsp;&nbsp;';
   $sqla  =$db->query('link'," `type` = '4' and `check` = '0' ORDER BY `id` ",'');
   while($rowa=mysql_fetch_array($sqla)){
    echo "<a href=\"admin.php?action=link&act=xgyl&id=$rowa[id]&fid=$row[id]\">$rowa[namem]</a>-";
 	 }
   echo "</div>";
















   $sql_bbs  =$db->query('link_class',"1  ORDER BY `px` ",'');
 	 while($row=mysql_fetch_array($sql_bbs)){
echo <<<end
<div class="admin_b">
<form method="POST" action="admin.php?action=link&act=xgflok&id=$row[id]" >
<input type="text" name="px" value="$row[px]" size=1/>
<input type="text" name="name" value="$row[name]" size=5/>
<input  class="submit" type="submit" value="编辑" name="b1" />
<a href="admin.php?action=link&act=scflts&id=$row[id]">删除</a>
</form>
</div>
end;

   echo '<div class="admin_a">&nbsp;&nbsp;&nbsp;&nbsp;';
   $sqla  =$db->query('link'," `fid` = '$row[id]' and `check` = '0' ORDER BY `id` LIMIT 0 ,4",'');
   while($rowa=mysql_fetch_array($sqla)){
    echo "<a href=\"admin.php?action=link&act=xgyl&id=$rowa[id]&fid=$row[id]\">$rowa[namem]</a>-";
 	 }
   echo "<a href=\"admin.php?action=link&act=gd&fid=$row[id]\"><font color=ff0000>更多..</font></a></div>";
   $l_s++;
	}
}
echo"<a href=\"admin.php?action=link&\">友链管理</a><br/>";
?>